package com.xrui.hbaseview.config;

import java.io.Serializable;

/**
 * This class represents a details of the server to connect to..
 */
public class ServerDetails implements Serializable {

    //region Constants
    private static final long serialVersionUID = -407779299748851910L;
    //endregion

    //region Variables
    /**
     * The name of the server.
     */
    private String host;
    /**
     * The port.
     */
    private String port;
    //endregion

    //region Constructor

    /**
     * Initializes a new instance of the {@link ServerDetails} class.
     *
     * @param host The server name.
     * @param port The server port.
     */
    public ServerDetails(String host, String port) {
        this.host = host;
        this.port = port;
    }

    /** Initializes a new instance of the {@link ServerDetails} class.
        *
        * @param host The server name.
        * @param port The server port.
        */
    public ServerDetails(String host, int port) {
        this.host = host;
        this.port = String.valueOf(port);
    }
    //endregion

    //region Public Properties

    /**
     * Gets the name of the server.
     *
     * @return The name of the server.
     */
    public String getHost() {
        return this.host;
    }

    /**
     * Gets a port.
     *
     * @return An {@link Integer} representing the port.
     */
    public String getPort() {
        return this.port;
    }
    //endregion

    //region Public Methods
    @Override
    public boolean equals(Object obj) {
        if (obj instanceof ServerDetails) {
            ServerDetails details = (ServerDetails) obj;
            return this.host.equals(details.host);
        }
        return false;
    }

    @Override
    public int hashCode() {
        return this.host.hashCode();
    }

    @Override
    public String toString() {
        return String.format("(%s):%s", host, port);
    }
    //endregion
}
